package com.dupengcheng.wx.entity;

import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Map;

@Component
public class WXSubscribeHandler implements WXMessageTypeHandler{


    private MessageTypeEnum type;

    @Override
    public MessageTypeEnum getType() {
        if (ObjectUtils.isEmpty(type)){
            this.type=MessageTypeEnum.SUBSCRIBE;
        }
        return this.type;
    }

    @Override
    public String execute(Map<String, String> body) {

        //关注后自动回复消息、
        String toUser = body.get("ToUserName");
        String fromUser=body.get("FromUserName");
        String msg="你好、感谢你的关注！！";
        String replyContent="<xml>\n" +
                "  <ToUserName><![CDATA["+fromUser+"]]></ToUserName>\n" +
                "  <FromUserName><![CDATA["+toUser+"]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA["+msg +"]]></Content>\n" +
                "</xml>\n";
        return replyContent;
    }
}
